/*
 * Teknei 2014 - All rights reserved
 */
package com.teknei.acabus.core.persistence.dao;

import java.util.List;

import com.teknei.acabus.PersistenceException;

/**
 * Generic interface for DAO access
 * @author Jorge Amaro
 * @version 1.0
 * @since 1.0
 *
 * @param <T> Entity class
 */
public interface GenericDAO<T> {

	/**
	 * Creates a record
	 * @param t entity
	 * @return the Entity saved instance
	 * @throws PersistenceException
	 */
	public T create(T t) throws PersistenceException;

	/**
	 * Finds a record based on its Id
	 * @param type the Class type of the record
	 * @param id the id of the record
	 * @return the instance
	 * @throws PersistenceException
	 */
	public T find(Class<T> type, Object id) throws PersistenceException;

	/**
	 * Updates the record instance
	 * @param t the instance
	 * @return the instance updated
	 * @throws PersistenceException
	 */
	public T update(T t) throws PersistenceException;

	/**
	 * Delete an instance of the class based on its id
	 * @param type the class 
	 * @param id the id of the record
	 * @throws PersistenceException
	 */
	public void delete(Class<T>  type, Object id) throws PersistenceException;

	/**
	 * Executes a find based on a named query
	 * @param queryName
	 * @return
	 * @throws PersistenceException
	 */
	public List<T>  findWithNamedQuery(String queryName) throws PersistenceException;

	/**
	 * Executes a native query and return the list elements
	 * @param sql
	 * @param type
	 * @return
	 * @throws PersistenceException
	 */
	List<T> findByNativeQuery(String sql, Class<T> type) throws PersistenceException;

	/**
	 * Finds all elements 
	 * @return the list
	 * @throws PersistenceException
	 */
	List<T> findAll() throws PersistenceException;

	/**
	 * Deletes an instance
	 * @param entity the instance
	 * @throws PersistenceException
	 */
	void delete(T entity) throws PersistenceException;

}
